package com.aijk.ehm.sys.mq.handler;

import com.aijk.ehm.sys.service.SysAdminService;
import com.alibaba.rocketmq.client.consumer.listener.ConsumeConcurrentlyContext;
import com.alibaba.rocketmq.client.consumer.listener.ConsumeConcurrentlyStatus;
import com.alibaba.rocketmq.common.message.MessageExt;
import com.lifesea.rocketmq.utils.handler.MessageHandler;
import com.lifesea.rocketmq.utils.message.MessageDecoder;
import com.lifesea.rocketmq.utils.message.codec.JsonMessageDecoder;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

/**
 * 公司删除操作
 */
@Component
public class CompanyDelHandler implements MessageHandler<Long> {
    @Resource
    private SysAdminService adminService;
    private static final Logger logger = LoggerFactory.getLogger(CompanyDelHandler.class);
    @Override
    public ConsumeConcurrentlyStatus process(Long company_id, MessageExt message, ConsumeConcurrentlyContext context) {
        logger.info("公司删除操作", message.getMsgId(), company_id);
        try {
                adminService.deleteWithCompanyId(company_id);
                return ConsumeConcurrentlyStatus.CONSUME_SUCCESS;
        } catch (Exception e) {
            logger.error("公司删除操作处理失败", e);
        }
        return ConsumeConcurrentlyStatus.RECONSUME_LATER;
    }

    @Override
    public MessageDecoder<Long> getMessageDecoder() {
        return new JsonMessageDecoder<Long>(Long.class);
    }
}
